package org.coco24.pmgame.pack

import com.badlogic.gdx.graphics.g2d.NinePatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.utils.Array
/**
 * Created by coco24 on 17-8-27.
 */
class Move
{
    constructor(cMoveId: Int, cRemainedPP: Int)
    {
        moveId = cMoveId
        pp = cRemainedPP
    }

    constructor(internalName: String)
    {
        this.internalName = internalName
    }

    constructor(moveId: Int)
    {
        this.moveId = moveId
    }

    var moveId: Int = 0
    var pp = 0
    var maxPP = 0
    var multiple = 1;
    var name = "???"
    var type = Type.UNKNOWN
    var power = 0
    var categroy = CATEGORY_PHISYCAL
    var accuracy = 1.0f
    var script = ""
    fun use()
    {
        if (checkUsable()) pp -= multiple
    }

    init
    {
        if (pp == -1) pp = maxPP
    }

    fun checkUsable(): Boolean
    {
        return pp - multiple >= 0
    }

    fun restore()
    {
        pp = maxPP;
    }
    companion object
    {
        val CATEGORY_PHISYCAL = 0
        val CATEGORY_SPECIAL = 1
        val CATEGORY_STATUS = 2

        fun getMoveNinePatchByType(regions: kotlin.Array<kotlin.Array<TextureRegion>>, type: Type): NinePatch
        {
            var x = 0;
            var y = 0
            when (type)
            {
                Type.GROUND ->
                {
                    x = 0; y = 0
                }
                Type.WATER ->
                {
                    x = 1; y = 0
                }
                Type.GHOST ->
                {
                    x = 2; y = 0
                }
                Type.BUG ->
                {
                    x = 3; y = 0
                }
                Type.FIGHTING ->
                {
                    x = 0; y = 1
                }
                Type.PSYCHIC ->
                {
                    x = 1; y = 1
                }
                Type.GRASS ->
                {
                    x = 2; y = 1
                }
                Type.DARK ->
                {
                    x = 3; y = 1
                }
                Type.NORMAL ->
                {
                    x = 0; y = 2
                }
                Type.POISON ->
                {
                    x = 1; y = 2
                }
                Type.ELECTRIC ->
                {
                    x = 2; y = 2
                }
                Type.UNKNOWN ->
                {
                    x = 3; y = 2
                }
                Type.STEEL ->
                {
                    x = 0; y = 3
                }
                Type.ROCK ->
                {
                    x = 1; y = 3
                }
                Type.DRAGON ->
                {
                    x = 2; y = 3
                }
                Type.FLYING ->
                {
                    x = 0; y = 4
                }
                Type.FIRE ->
                {
                    x = 1; y = 4
                }
                Type.ICE ->
                {
                    x = 2; y = 4
                }

            }
            return NinePatch(regions[y][x], 18, 20, 20, 16)
        }
    }


    enum class Category
    {
        PHISYCAL, SPECIAL, STATUS;

        companion object
        {
            fun getFromString(string: String): Category
            {
                return when (string)
                {
                    "PHISYCAL" -> PHISYCAL
                    "SPECIAL" -> SPECIAL
                    "STATUS" -> STATUS
                    else -> PHISYCAL
                }
            }
        }
    }

    var category = Category.PHISYCAL
    var internalName = "???"
    var priority = 0//优先级
    var description = "Unknown Move."
    var scriptFlags = initIntArray(8)
            fun initIntArray(size : Int):Array<Int>
            {
                val array = Array<Int>()
                for(i in 0 until size)
                {
                    array.add(0)
                }
                return array
            }
    enum class Flag(char: Char)
    {
        MAKES_CONTACT('a');

        val char = char

        companion object
        {
            fun getByChar(char: Char): Flag
            {
                return when (char)
                {
                    MAKES_CONTACT.char -> MAKES_CONTACT
                    else -> MAKES_CONTACT
                }
            }
        }
    }

    enum class Target
    {
        SINGLE_NONUSER, NO_TARGET, RANDOM_OPPOSING,//4
        ALL_OPPOSING, ALL_NONUSER,//8
        USER, USERS_SIDE, BOTH_SIDES, OPPOSING_SIDE, PARTNER, USER_OR_PARTNER, SINGLE_OPPOSING, OPPOSITE_OPPOSING;

    }

    var target = Target.SINGLE_NONUSER
    var flags = Array<Float>()

}